/*
 * @Author: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @Date: 2022-11-02 08:35:22
 * @LastEditors: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @LastEditTime: 2022-11-04 19:54:27
 * @FilePath: \宏烨找房\agent\src\store\loginReducer.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { fetch_data } from "./loginAction";

const initState = {
    token: '',
    user: JSON.parse(localStorage.getItem('user')) || {}
}

export const loginReducer = (state = initState, action) => {
    switch (action.type) {
        case fetch_data: {
            console.log(action)
            localStorage.setItem('token', JSON.stringify(action.payload))
            localStorage.setItem('user', JSON.stringify(action.sss))
        }

            return {
                ...state,
                token: action.payload,
                user: action.sss,

            }
        default: {
            return state
        }
    }

}